﻿using IMark.DAO;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.Admin.Product
{
    public partial class UpdatePromotion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Utils.CheckAuthentication())
            {
                string ID = Request.QueryString["ID"] ?? String.Empty;
                string from = Request.QueryString["from"] ?? String.Empty;
                string to = Request.QueryString["to"] ?? String.Empty;
                string discount = Request.QueryString["discount"] ?? String.Empty;
                if (ID == String.Empty)
                {
                    Response.Redirect("~/Admin/Product/Index.aspx");
                }
                else
                {
                    SAN_PHAM sanPham = SanPhamModels.GetByID(int.Parse(ID));
                    sanPham.NgaySua = DateTime.Now;
                    sanPham.NgayBatDau = DateTime.ParseExact(from, "dd/MM/yyyy", new CultureInfo("en-US"));
                    sanPham.NgayKetThuc = DateTime.ParseExact(to, "dd/MM/yyyy", new CultureInfo("en-US"));
                    sanPham.GiamGia = int.Parse(discount);
                    bool status = SanPhamModels.UpdatePromotion(sanPham);
                    if (status)
                    {
                        Session["Info"] = "<div class='alert alert-success'>Cập nhật khuyến mãi thành công !!!</div>";
                    }
                    else
                    {
                        Session["Info"] = "<div class='alert alert-danger'>Đã xảy ra lỗi, vui lòng thử lại !!!</div>";
                    }
                    Response.Redirect("~/Admin/Product/Index.aspx");
                }
            }

        }
    }
}